{# Copyright The IETF Trust 2017, All Rights Reserved #}
{% load origin django_bootstrap5 %}
{% origin %}
{% load person_filters ietf_filters %}
<table class="my-3 table table-sm table-borderless">
    <tbody class="meta border-top">
        <tr>
            <th scope="row">Request</th>
            <th scope="row">Review of</th>
            <td>
                {% if review_req.requested_rev %}
                    <a href="{% url "ietf.doc.views_doc.document_main" name=review_req.doc.name rev=review_req.requested_rev %}">
                        {{ review_req.doc.name }}-{{ review_req.requested_rev }}
                    </a>
                {% else %}
                    <a href="{% url "ietf.doc.views_doc.document_main" name=review_req.doc.name %}">{{ review_req.doc.name }}</a>
                {% endif %}
            </td>
        </tr>
        <tr>
            <td></td>
            <th scope="row">Requested revision</th>
            <td>
                {% if review_req.requested_rev %}
                    {{ review_req.requested_rev }}
                {% else %}
                    No specific revision
                {% endif %}
                {% if review_req.reviewed_rev != review_req.doc.rev %}
                    <span class="text-body-secondary">(document currently at {{ review_req.doc.rev }})</span>
                {% endif %}
            </td>
        </tr>
        <tr>
            <td></td>
            <th scope="row">Type</th>
            <td>{{ review_req.type.name }} Review</td>
        </tr>
        <tr>
            <td></td>
            <th scope="row">Team</th>
            <td>
                {% if review_req %}
                    {{ review_req.team.name }}
                {% else %}
                    {{ doc.group.name }}
                {% endif %}
                (<a href="{% url 'ietf.group.views.review_requests' group_type=review_req.team.type_id acronym=review_req.team.acronym %}">{{ review_req.team.acronym }}</a>)
            </td>
        </tr>
        <tr>
            <td></td>
            <th scope="row">Deadline</th>
            <td>
                {{ review_req.deadline|date:"Y-m-d" }}
                {% if can_edit_deadline %}
                    <a class="btn btn-primary btn-sm"
                       href="{% url "ietf.doc.views_review.edit_deadline" name=doc.name request_id=review_req.pk %}">
                        <i class="bi bi-pencil"></i>
                        Edit
                    </a>
                {% endif %}
            </td>
        </tr>
        <tr>
            <td></td>
            <th scope="row">Requested</th>
            <td>{{ review_req.time|date:"Y-m-d" }}</td>
        </tr>
        {% if review_req.requested_by.name != "(System)" %}
            <tr>
                <td></td>
                <th scope="row">Requested by</th>
                <td>{% person_link review_req.requested_by %}</td>
            </tr>
        {% endif %}
        {% if review_req.doc.authors %}
            <tr>
                <td></td>
                <th scope="row">Authors</th>
                <td>
                    {% for author in review_req.doc.authors %}
                        {% person_link author %}{% if not forloop.last %},{% endif %}
                    {% endfor %}
                </td>
            </tr>
        {% endif %}
        {% if wg_chairs %}
            <tr>
                <td></td>
                <th scope="row">WG chairs</th>
                <td>
                    {% for chair in wg_chairs %}
                        {% person_link chair %}{% if not forloop.last %},{% endif %}
                    {% endfor %}
                </td>
            </tr>
        {% endif %}
        {% if review_req.doc.time %}
            <tr>
                <th scope="row">
                </th>
                <th scope="row">
                    I-D last updated
                </th>
                <td>
                    {{ review_req.doc.time|date:"Y-m-d" }}
                    {% if review_req.doc.pub_date %}
                        <span class="text-body-secondary">(Latest revision {{ review_req.doc.pub_date|date:"Y-m-d" }})</span>
                    {% endif %}
                </td>
            </tr>
        {% endif %}
        {% if iesg_state_summary %}
            <tr>
                <th scope="row">
                </th>
                <th scope="row">
                    IESG document state
                </th>
                <td>
                    {{ iesg_state_summary }}
                </td>
            </tr>
        {% endif %}
        <tr>
            <th scope="row">
            </th>
            <th scope="row">
                Completed reviews
            </th>
            <td>
                {% for a in review_req.all_completed_assignments_for_doc %}
                    {% if a.review %}
                        <a href="{% url "ietf.doc.views_doc.document_main" name=a.review.name %}">{{ a.review_request.team.acronym|capfirst }} {{ a.review_request.type.name }} review of -{{ a.reviewed_rev|default:"??" }}</a>
                        by {% person_link a.reviewer.person %}
                    {% else %}
                        {{ a.review_request.team.acronym|capfirst }} {{ a.review_request.type.name }} review of -{{ a.reviewed_rev|default:"??" }} by {% person_link a.reviewer.person %}
                    {% endif %}
                    {% if a.reviewed_rev and a.reviewed_rev != a.review_request.doc.rev %}
                        (<a href="{{ rfcdiff_base_url }}?url1={{ a.review_request.doc.name }}-{{ a.reviewed_rev }}&amp;url2={{ a.review_request.doc.name }}-{{ a.review_request.doc.rev }}">diff</a>)
                    {% endif %}
                    <br>
                {% endfor %}
            </td>
        </tr>
        {% if review_req.comment %}
            <tr>
                <th scope="row">
                </th>
                <th scope="row">
                    Comments
                </th>
                <td>
                    <pre class="pasted">{{review_req.comment}}</pre>
                    {% if can_edit_comment %}
                        <a class="btn btn-primary btn-sm"
                           href="{% url "ietf.doc.views_review.edit_comment" name=doc.name request_id=review_req.pk %}">
                            <i class="bi bi-pencil">
                            </i>
                            Edit comment
                        </a>
                    {% endif %}
                </td>
            </tr>
        {% endif %}
    </tbody>
    {% for assignment in assignments %}
        <tbody class="meta border-top">
            <tr>
                <th scope="row">
                    {% if forloop.first %}Assignment{{ assignments|pluralize }}{% endif %}
                </th>
                <th scope="row">
                    Reviewer
                </th>
                <td>
                    <strong>{% person_link assignment.reviewer.person %}</strong>
                    {% if assignment.can_reject_reviewer_assignment or assignment.can_accept_reviewer_assignment %}
                        <div class="reviewer-assignment-not-accepted">
                            {% if assignment.state_id == "assigned" %}
                                Assignment not accepted yet
                            {% elif assignment.state_id == "rejected" %}
                                <span class="text-danger">Assignment rejected</span>
                            {% else %}
                                <span class="text-success">Assignment accepted</span>
                            {% endif %}
                            <br>
                            <div class="mt-2">
                                {% if assignment.can_reject_reviewer_assignment %}
                                    <a class="btn btn-danger btn-sm"
                                       href="{% url "ietf.doc.views_review.reject_reviewer_assignment" name=doc.name assignment_id=assignment.pk %}">
                                        <i class="bi bi-x-circle">
                                        </i>
                                        Reject
                                    </a>
                                {% endif %}
                                {% if assignment.can_accept_reviewer_assignment %}
                                    <form class="d-inline"
                                          method="post"
                                          action="{% url "ietf.doc.views_review.review_request" name=doc.name request_id=review_req.pk %}">
                                        {% csrf_token %}
                                        <button class="btn btn-success btn-sm"
                                                type="submit"
                                                name="action"
                                                value="accept">
                                            <i class="bi bi-check">
                                            </i>
                                            Accept
                                        </button>
                                    </form>
                                {% endif %}
                            </div>
                        </div>
                    {% endif %}
                </td>
            </tr>
            <tr>
                <th scope="row">
                </th>
                <th scope="row">
                    State
                </th>
                <td>
                    {{ assignment.state.name|badgeify }}
                    {% if snapshot %}
                        <span class="badge rounded-pill text-bg-warning">
                            Snapshot
                        </span>
                    {% endif %}
                </td>
            </tr>
	    {% if doc == assignment.review %}
	    <tr>
	      <th scope="row">
	      </th>
	      <th scope="row">
		Request
	      </th>
	      <td>
		<a href="{% url "ietf.doc.views_review.review_request" request_id=review_req.id name=review_req.doc.name %}">
		  {{ review_req }}
		</a>
	      </td>
	    </tr>
	    {% endif %}
            {% if assignment.state_id != "withdrawn" and assignment.state_id != "no-response" and assignment.state_id != "rejected" and doc != assignment.review%}
                <tr>
                    <th scope="row">
                    </th>
                    <th scope="row">
                        Review
                    </th>
                    <td>
                        {% if assignment.review %}
                            <a href="{{ assignment.review.get_absolute_url }}">
                                {{ assignment.review.name }}
                            </a>
                        {% elif assignment.state_id == "assigned" or assignment.state_id == "accepted" %}
                            Not completed yet
                        {% else %}
                            Not available
                        {% endif %}
                        <br>
                        <div class="mt-2">
                            {% if assignment.can_complete_review %}
                                <a class="btn btn-primary btn-sm"
                                   href="{% url "ietf.doc.views_review.complete_review" name=doc.name assignment_id=assignment.pk %}">
                                    <i class="bi bi-pencil">
                                    </i>
                                    {% if assignment.state_id == "assigned" or assignment.state_id == "accepted" %}
                                        Complete review
                                    {% else %}
                                        Correct review
                                    {% endif %}
                                </a>
                            {% endif %}
                            {% if assignment.state_id == "assigned" or assignment.state_id == "accepted" %}
                                {% if can_assign_reviewer %}
                                    <a class="btn btn-danger btn-sm"
                                       href="{% url "ietf.doc.views_review.mark_reviewer_assignment_no_response" name=doc.name assignment_id=assignment.pk %}">
                                        <i class="bi bi-question-circle">
                                        </i>
                                        No response
                                    </a>
                                    <a class="btn btn-danger btn-sm"
                                       href="{% url "ietf.doc.views_review.withdraw_reviewer_assignment" name=doc.name assignment_id=assignment.pk %}">
                                        <i class="bi bi-x-circle">
                                        </i>
                                        Withdraw
                                    </a>
                                {% endif %}
                            {% endif %}
                        </div>
                    </td>
                </tr>
            {% endif %}
            {% if assignment.review and assignment.review.external_url %}
                <tr>
                    <th scope="row">
                    </th>
                    <th scope="row">
                        Posted at
                    </th>
                    <td>
                        <a href="{{ assignment.review.external_url }}">
                            {{ assignment.review.external_url }}
                        </a>
                    </td>
                </tr>
            {% endif %}
            {% if assignment.reviewed_rev %}
                <tr>
                    <th scope="row">
                    </th>
                    <th scope="row">
                        Reviewed revision
                    </th>
                    <td>
                        <a href="{% url "ietf.doc.views_doc.document_main" name=review_req.doc.name rev=assignment.reviewed_rev %}">{{ assignment.reviewed_rev }}</a>
                        {% if assignment.reviewed_rev != review_req.doc.rev %}(document currently at {{ review_req.doc.rev }}){% endif %}
                    </td>
                </tr>
            {% endif %}
            {% if assignment.result %}
                <tr>
                    <th scope="row">
                    </th>
                    <th scope="row">
                        Result
                    </th>
                    <td>
                        {{ assignment.result.name|badgeify }}
                    </td>
                </tr>
            {% endif %}
            {% if assignment.state_id == "completed" or assignment.state_id == "part-completed" %}
                <tr>
                    <th scope="row">
                    </th>
                    <th scope="row">
                        Completed
                    </th>
                    <td>
                        {{ assignment.completed_on|date:"Y-m-d" }}
                    </td>
                </tr>
            {% endif %}
        </tbody>
    {% endfor %}
</table>
{% if can_assign_reviewer %}
    <a class="btn btn-primary"
       href="{% url "ietf.doc.views_review.assign_reviewer" name=doc.name request_id=review_req.pk %}">
        <i class="bi bi-forward">
        </i>
        Assign reviewer
    </a>
{% endif %}
